package com.sky.mapper;

import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {


    //新增套餐-->保存到中间表,->修改套餐
    @Insert("insert into setmeal_dish values (null,#{setmealId},#{dishId},#{name},#{price},#{copies})")
    void save(SetmealDish setmealDish);

    //根据套餐id查询//回显套餐->根据id查询套餐
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> findBySetmealId(Long setmealId);

    //根据套餐id删除-->根据套餐id从中间查询菜品集合--> //修改套餐,先删菜品后加
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteBySetmealId(Long setmealId);

    //根据套餐id查询对应的菜品信息
    @Select("select d.* from setmeal_dish sd join dish d on sd.dish_id = d.id where sd.setmeal_id=#{setmealId}")
    List<Dish> findDishesBySetmealId(Long id);


    //根据id查询套餐的菜品列表
    @Select("select d.name,d.image,d.description,sd.copies from setmeal_dish sd join dish d on sd.dish_id = d.id where sd.setmeal_id=#{id}")
    List<DishItemVO> findById(Long id);

    //根据id查询套餐的菜品列表
    @Select("select s.copies,d.description,d.name,d.image from setmeal_dish s left join dish d on d.id = s.dish_id where setmeal_id=#{id}")
    List<DishItemVO> findDishList(Long id);
}

